package com.huidian.resource.server.service;

import com.huidian.cache.aop.ClearCache;
import com.huidian.resource.client.enums.EmBaseCacheDef;
import com.huidian.resource.server.dao.MeterMapper;
import com.huidian.resource.server.entity.Meter;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * @author tjs
 */
@Service
public class MeterServiceImpl implements IMeterService {
    @Resource
    private MeterMapper meterMapper;

    @Override
    public List<Meter> selectList(Meter meter) {
        return null;
    }

    @Override
    public Meter selectOne(Meter meter) {
        return meterMapper.selectByPrimaryKey(meter.getMeterId());
    }

    @Override
    public long selectTotal(Meter meter) {
        return 0;
    }

    @Override
    public int delete(Meter meter) {
        return 0;
    }

    @Override
    public void addBatch(List<Meter> list) {

    }

    @Override
    public void addBatch(List<Meter> list, int batchSize) {

    }

    @Override
    public void addSelective(Meter meter) {

    }

    @Override
    @ClearCache(idKey = EmBaseCacheDef.EM_METER_ID_KEY,idCache = EmBaseCacheDef.EM_METER_ID_CACHE,indexKey = EmBaseCacheDef.EM_METER_INDEX_KEY,indexCache = EmBaseCacheDef.EM_METER_INDEX_CACHE,
            daoBeanName = "meterServiceImpl",daoMethodName = "selectBatchIds",daoParamClazz = {Collection.class},
            cacheManager = EmBaseCacheDef.EM_METER_CACHE_MANAGER,deleteKeys = EmBaseCacheDef.EM_METER_CACHE_DEL_METHOD + "#meter)"
    )
    public void updateObj(Meter meter) {
        meterMapper.updateByPrimaryKey(meter);
    }

    @Override
    public List<Meter> selectBatchIds(Collection<Long> meterIdList){
        Example example = new Example(Meter.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("meterId",meterIdList);
        return meterMapper.selectByExample(example);
    }
}
